**************************************************************************************************************************************************
****************************** Wealth-Income Ratios in Free Market Capitalism: Switzerland, 1900-2020 ********************************************
**************************************************************************************************************************************************

clear all
set more off
set scheme s1color  

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: January, 25 2023

*** set this path to the current directory
*** global mypath "C:\Users\EBaselgia\Dropbox\WIR_project\Publication_process\replication"


** This Do-file generates the final data-set used in the analysis
** The sources of the various time series are described in detail in the online appendix.
cd "$mypath/raw_data/"
import excel "CH_wir_raw.xlsx", sheet("Sheet1") cellrange(A4:BJ125) firstrow

cd "$mypath/"
mkdir final_data
cd "$mypath/final_data/"
save "WIR_final.dta", replace
use "WIR_final.dta", clear


***************************
**** data construction ****
***************************
drop varname

***** Population *****
gen ch_pop_total = (ch_pop_0101+ ch_pop_3112)/2
drop ch_pop_0101 ch_pop_3112
label variable ch_pop_total "total population"
gen ch_pop_gr = ch_pop_total / ch_pop_total[_n-1] -1
label variable ch_pop_gr "population growth rate"


***** Price Index*****
gen ch_cpi = ch_cpi_1914_2020/ch_cpi_1914_2020[121]
replace ch_cpi = ch_cpi[15]/ ch_cpi_1900_1920[15] * ch_cpi_1900_1920 if year<1914
drop ch_cpi_1914_2020 ch_cpi_1900_1920
label variable ch_cpi "Consumer Price Index (LIK), composite"



******************************
*****  Private Wealth    *****
******************************
gen ch_pW_T =.
replace ch_pW_T = ch_pW_fin + ch_pW_hous - ch_pW_liabilities
replace ch_pW_T = ch_pW_netW_schmidt if year < 2000
gen ch_taxW_pensW = ch_pW_taxW + ch_pW_pensW_hist
gen ch_gr_taxW_pensW = ch_taxW_pensW / ch_taxW_pens[_n-1]
gen pW_calc =.
replace pW_calc = ch_pW_netW_schmidt if year==1981
forvalues i = 1/81 {
   replace pW_calc = pW_calc[_n+1]/ch_gr_taxW_pensW[_n+1] if missing(pW_calc) 
}
replace ch_pW_T = pW_calc if year<1981
drop ch_taxW_pensW ch_gr_taxW_pensW pW_calc ch_pW_taxW ch_pW_pensW_hist
gen ch_pW_T_R = ch_pW_T / ch_cpi
gen ch_pW_PC = ch_pW_T / ch_pop_total *1000000
gen ch_pW_PC_R = ch_pW_T_R / ch_pop_total *1000000

label variable ch_pW_T "Net Private Wealth (total), in million nominal CHF"
label variable ch_pW_T_R "Net Private Wealth (total), in million real 2020-CHF"
label variable ch_pW_PC "Net Private Wealth per capita, in nominal CHF"
label variable ch_pW_PC_R "Net Private Wealth per capita, in real 2020-CHF"
label variable ch_pW_netW_schmidt "Net Private Wealth estimates by Schmidt, in million nominal CHF"

***** Components of Private Wealth*****
*** Gross Housing Wealth
gen ch_pW_housing_T = ch_pW_hous
drop ch_pW_hous
gen ch_pW_housing_T_R = ch_pW_housing_T / ch_cpi
gen ch_pW_housing_PC = ch_pW_housing_T / ch_pop_total *1000000
gen ch_pW_housing_PC_R = ch_pW_housing_PC / ch_cpi

label variable ch_pW_housing_T "Gross Housing Private Wealth (total), in million nominal CHF"
label variable ch_pW_housing_T_R "Gross Housing Private Wealth (total), in million real 2020-CHF"
label variable ch_pW_housing_PC "Gross Housing Private Wealth per capita, in nominal CHF"
label variable ch_pW_housing_PC_R "Gross Housing Private Wealth per capita, in real 2020-CHF"


*** Pension Wealth
gen ch_pW_pension_T = ch_pW_pens
drop ch_pW_pens
gen ch_pW_pension_T_R = ch_pW_pension_T / ch_cpi
gen ch_pW_pension_PC = ch_pW_pension_T / ch_pop_total *1000000
gen ch_pW_pension_PC_R = ch_pW_pension_PC / ch_cpi

label variable ch_pW_pension_T "Net Pension Private Wealth (total), in million nominal CHF"
label variable ch_pW_pension_T_R "Net Pension Private Wealth (total), in million real 2020-CHF"
label variable ch_pW_pension_PC "Net Pension Private Wealth per capita, in nominal CHF"
label variable ch_pW_pension_PC_R "Net Pension Private Wealth per capita, in real 2020-CHF"


*** Net Financial Wealth
gen ch_pW_netfin_T = ch_pW_T - ch_pW_housing_T - ch_pW_pension_T
gen ch_pW_netfin_T_R = ch_pW_T_R - ch_pW_housing_T_R - ch_pW_pension_T_R
gen ch_pW_netfin_PC = ch_pW_PC - ch_pW_housing_PC - ch_pW_pension_PC
gen ch_pW_netfin_PC_R = ch_pW_PC_R - ch_pW_housing_PC_R - ch_pW_pension_PC_R

label variable ch_pW_netfin_T "Net Financial Private Wealth (total), in million nominal CHF"
label variable ch_pW_netfin_T_R "Net Financial Private Wealth (total), in million real 2020-CHF"
label variable ch_pW_netfin_PC "Net Financial Private Wealth per capita, in nominal CHF"
label variable ch_pW_netfin_PC_R "Net Financial Private Wealth per capita, in real 2020-CHF"

*** Gross Financial Wealth
gen ch_pW_grossfin_T = ch_pW_fin 
gen ch_pW_grossfin_T_R = ch_pW_grossfin_T / ch_cpi
gen ch_pW_grossfin_PC = ch_pW_grossfin_T / ch_pop_total *1000000
gen ch_pW_grossfin_PC_R = ch_pW_grossfin_PC / ch_cpi
drop ch_pW_fin

label variable ch_pW_grossfin_T "Gross Financial Private Wealth (total), in million nominal CHF"
label variable ch_pW_grossfin_T_R "Gross Financial Private Wealth (total), in million real 2020-CHF"
label variable ch_pW_grossfin_PC "Gross Financial Private Wealth per capita, in nominal CHF"
label variable ch_pW_grossfin_PC_R "Gross Financial Private Wealth per capita, in real 2020-CHF"


*** Financial Liabilities
gen ch_pW_liabil_T = ch_pW_liabilities 
gen ch_pW_liabil_T_R = ch_pW_liabil_T / ch_cpi
gen ch_pW_liabil_PC = ch_pW_liabil_T / ch_pop_total *1000000
gen ch_pW_liabil_PC_R = ch_pW_liabil_PC / ch_cpi
drop ch_pW_liabilities

label variable ch_pW_liabil_T "Private Financial Liabilities(total), in million nominal CHF"
label variable ch_pW_liabil_T_R "Private Financial Liabilities(total), in million real 2020-CHF"
label variable ch_pW_liabil_PC "Private Financial Liabilities per capita, in nominal CHF"
label variable ch_pW_liabil_PC_R "Private Financial Liabilities per capita, in real 2020-CHF"


*** Financial Liabilities - Mortgages
gen ch_pW_mortgages_T = ch_pW_mortgages 
gen ch_pW_mortgages_T_R = ch_pW_mortgages_T / ch_cpi
gen ch_pW_mortgages_PC = ch_pW_mortgages_T / ch_pop_total *1000000
gen ch_pW_mortgages_PC_R = ch_pW_mortgages_PC / ch_cpi
drop ch_pW_mortgages

label variable ch_pW_mortgages_T "Private Mortgages(total), in million nominal CHF"
label variable ch_pW_mortgages_T_R "Private Mortgages(total), in million real 2020-CHF"
label variable ch_pW_mortgages_PC "Private Mortgages per capita, in nominal CHF"
label variable ch_pW_mortgages_PC_R "Private Mortgages per capita, in real 2020-CHF"


**** Net Financinal Wealth (including Pension Wealth)
/*
We need this data to decompose total private net wealth into total financial wealth including pension wealth and housing wealth
this will allow us to decompose the changes of these two wealth categories into a savings and a capital gains component
*/
label variable ch_pW_netfin_total_T "Total Net Private Financial Wealth (including Pension wealth), in million nominal CHF"
label variable ch_pW_netfin_total_trans "Savings Component of total Net Private Financial Wealth (including Pension wealth), in million nominal CHF"
label variable ch_pW_netfin_total_cp "Capital-gains Component of total Net Private Financial Wealth (including Pension wealth), in million nominal CHF"
label variable ch_pW_netfin_total_statchange "Statistical Changes of total Net Private Financial Wealth (including Pension wealth), in million nominal CHF"
label variable ch_pW_pension_statchange "Statistical Changes of Pension Wealth (including Pension wealth), in million nominal CHF"

    

******************************
*****   Public Wealth    *****
****************************** 

*** Municipality level
label variable ch_gW_nonfin_gdn "Government Non-Financial Wealth at the municipality-level, in million nominal CHF"
label variable ch_gW_fin_gdn "Government Financial Wealth at the municipality-level, in million nominal CHF"
label variable ch_gW_liab_gdn "Government Liabilities at the municipality-level, in million nominal CHF"
label variable ch_gW_net_gdn "Net Government Wealth at the municipality-level, in million nominal CHF"

*** Cantonal level (state-level)
label variable ch_gW_nonfin_ktn "Government Non-Financial Wealth at the cantonal-level, in million nominal CHF"
label variable ch_gW_fin_ktn "Government Financial Wealth at the cantonal-level, in million nominal CHF"
label variable ch_gW_liab_ktn "Government Liabilities at the cantonal-level, in million nominal CHF"
label variable ch_gW_net_ktn "Net Government Wealth at the cantonal-level, in million nominal CHF"

*** Federal level
label variable ch_gW_nonfin_bund "Government Non-Financial Wealth at the federal-level, in million nominal CHF"
label variable ch_gW_fin_bund "Government Financial Wealth at the federal-level, in million nominal CHF"
label variable ch_gW_liab_bund "Government Liabilities at the federal-level, in million nominal CHF"
label variable ch_gW_net_bund "Net Government Wealth at the federal-level, in million nominal CHF"

*** Social Insurance
label variable ch_gW_nonfin_sv "Government Non-Financial Wealth - Social Insurance, in million nominal CHF"
label variable ch_gW_fin_sv "Government Financial Wealth - Social Insurance, in million nominal CHF"
label variable ch_gW_liab_sv "Government Liabilities - Social Insurance, in million nominal CHF"
label variable ch_gW_net_sv "Net Government Wealth - Social Insurance, in million nominal CHF"

*** Total State (= Municipality+Cantonal+Federal+Social Insurance)
label variable ch_gW_nonfin_staat "Government Non-Financial Wealth - State, in million nominal CHF"
label variable ch_gW_fin_staat "Government Financial Wealth - State, in million nominal CHF"
label variable ch_gW_liab_staat "Government Liabilities - State, in million nominal CHF"
label variable ch_gW_net_staat "Net Government Wealth - State, in million nominal CHF"


*** correction non-financial wealth at the federal-level (Bund) 
gen ch_gW_nonfin_gr_bund = ch_gW_nonfin_bund / ch_gW_nonfin_bund[_n-1]
egen ch_gW_nonfin_grmean1 = mean(ch_gW_nonfin_gr_bund) if year>1997
egen ch_gW_nonfin_grmean2 = mean(ch_gW_nonfin_gr_bund) if year !=2007 & year !=2008 & year>1997
gen ch_gW_nonfin_bund_cor = ch_gW_nonfin_bund if year>2007
forvalues i = 1/2 {
   replace ch_gW_nonfin_bund_cor = ch_gW_nonfin_bund_cor[_n+1]/ch_gW_nonfin_grmean2[121] if missing(ch_gW_nonfin_bund_cor) 
}
forvalues i = 1/16 {
   replace ch_gW_nonfin_bund_cor = ch_gW_nonfin_bund_cor[_n+1]/ch_gW_nonfin_gr_bund[_n+1] if missing(ch_gW_nonfin_bund_cor) 
}

label variable ch_gW_nonfin_gr_bund "Growth Rate Government Non-Financial Wealth - State"
label variable ch_gW_nonfin_grmean1 "Average Growth Rate Government Non-Financial Wealth - 1998-2008"
label variable ch_gW_nonfin_grmean2 "Average Growth Rate Government Non-Financial Wealth - 1998-2008 without 2007/2008"
label variable ch_gW_nonfin_bund_cor "Corrected Government Non-Financial Wealth at the federal-level, in million nominal CHF"

gen ch_gW_net_bund_cor = ch_gW_nonfin_bund_cor + ch_gW_fin_bund - ch_gW_liab_bund
gen ch_gW_nonfin_staat_cor = ch_gW_nonfin_gdn + ch_gW_nonfin_ktn + ch_gW_nonfin_bund_cor + ch_gW_nonfin_sv
gen ch_gW_net_staat_cor = ch_gW_nonfin_staat_cor + ch_gW_fin_staat - ch_gW_liab_staat
label variable ch_gW_net_bund_cor "Corrected Net Government Wealth at the federal-level, in million nominal CHF"
label variable ch_gW_nonfin_staat_cor "Corrected Government Non-Financial Wealth - State, in million nominal CHF"
label variable ch_gW_net_staat_cor "Corrected Net Government Wealth - State, in million nominal CHF"


***********************************************
*****  National and Net Foreign Wealth    *****
***********************************************
gen ch_nW_T = ch_pW_T + ch_gW_net_staat_cor
label variable ch_nW_T "Net National Wealth (total), in million nominal CHF"


gen ch_nfaW_T = ch_foreignW_net9020
label variable ch_nfaW_T "Net Foreign Wealth (total), in million nominal CHF"
drop ch_foreignW_net9020 
gen ch_domW_T = ch_nW_T - ch_nfaW_T
label variable ch_domW_T "Net Domestic Wealth (total), in million nominal CHF"


gen ch_nW_T_R = ch_nW_T / ch_cpi
gen ch_nW_PC = ch_nW_T / ch_pop_total *1000000
gen ch_nW_PC_R = ch_nW_T_R / ch_pop_total *1000000

label variable ch_nW_T_R "National Wealth (total), in million real 2020-CHF"
label variable ch_nW_PC "National Wealth per capita, in nominal CHF"
label variable ch_nW_PC_R "National Wealth per capita, in real 2020-CHF"


***********************************
*****  Net National Income    *****
***********************************
gen ch_nni_T = ch_nni_vgr
gen ch_gr_nni_hsso_7895 = ch_nni_hsso_7895 / ch_nni_hsso_7895[_n-1]
forvalues i = 1/5 {
   replace ch_nni_T = ch_nni_T[_n+1]/ch_gr_nni_hsso_7895[_n+1] if missing(ch_nni_T) 
}
gen ch_gr_nni_hsso_4890 = ch_nni_hsso_4890 / ch_nni_hsso_4890[_n-1]
forvalues i = 1/42 {
   replace ch_nni_T = ch_nni_T[_n+1]/ch_gr_nni_hsso_4890[_n+1] if missing(ch_nni_T) 
}
gen ch_nni_gr_hsso_4660 = ch_nni_hsso_4660 / ch_nni_hsso_4660[_n-1]
forvalues i = 1/2 {
   replace ch_nni_T = ch_nni_T[_n+1]/ch_nni_gr_hsso_4660[_n+1] if missing(ch_nni_T) 
}
gen ch_nni_gr_hsso_3846 = ch_nni_hsso_3846 / ch_nni_hsso_3846[_n-1]
forvalues i = 1/8 {
   replace ch_nni_T = ch_nni_T[_n+1]/ch_nni_gr_hsso_3846[_n+1] if missing(ch_nni_T) 
}
gen ch_nni_gr_hsso_2938 = ch_nni_hsso_2938 / ch_nni_hsso_2938[_n-1]
forvalues i = 1/9 {
   replace ch_nni_T = ch_nni_T[_n+1]/ch_nni_gr_hsso_2938[_n+1] if missing(ch_nni_T) 
}
gen ch_gdp_gr_stohr = ch_gdp_stohr / ch_gdp_stohr[_n-1]
forvalues i = 1/29 {
   replace ch_nni_T = ch_nni_T[_n+1]/ch_gdp_gr_stohr[_n+1] if missing(ch_nni_T) 
}

drop ch_gr_nni_hsso_7895 ch_gr_nni_hsso_4890 ch_nni_gr_hsso_4660 ch_nni_gr_hsso_3846 ch_nni_gr_hsso_2938 ch_gdp_gr_stohr ch_nni_hsso_7895 ch_nni_hsso_4890 ch_nni_hsso_4660 ch_nni_hsso_3846 ch_nni_hsso_2938 ch_gdp_stohr
gen ch_nni_T_R = ch_nni_T / ch_cpi
gen ch_nni_PC = ch_nni_T / ch_pop_total *1000000
gen ch_nni_PC_R = ch_nni_T_R / ch_pop_total *1000000
label variable ch_nni_T "Net National Income (total), in million nominal CHF"
label variable ch_nni_T_R "Net National Income (total), in million real 2020-CHF"
label variable ch_nni_PC "Net National Income per capita, in nominal CHF"
label variable ch_nni_PC_R "Net National Income per capita, in real 2020-CHF"

gen ch_nni_gr_T_R = ch_nni_T_R / ch_nni_T_R[_n-1] -1
label variable ch_nni_gr_T_R "Real Growth of Net National Income"
gen ch_nni_gr_PC_R = ch_nni_PC_R / ch_nni_PC_R[_n-1] -1
label variable ch_nni_gr_PC_R "Real Growth of per capital Net National Income"


***********************************************************
***** A.5 Capital and Labor Shares in National Income *****
***********************************************************
// we construct capital and labor shares follwing alvardeo et. al (2017) (see table 3 and table4 in their appendix)
*** Taxes on Production (net) received by general gov. sector (S13)
gen ch_net_prod_tax = ch_D2S13_vgr - ch_D3S13_vgr

*** Personal component of Primary Income of corporate Sector (B5n, S11 +S12)
gen ch_priminc_corpS = ch_B5S11_vgr + ch_B5S12_vgr

*** Capital component of imputed taxes on production (net) - in proportion to income
gen ch_cap_imputed_tax = ch_net_prod_tax / (ch_B2nS14_vgr + ch_D4S14_recieved_vgr - ch_D4S14_paid_vgr + ch_priminc_corpS + ch_D1S1_vgr) * (ch_B2nS14_vgr + ch_D4S14_recieved_vgr - ch_D4S14_paid_vgr + ch_priminc_corpS) 

*** Labor component of imputed taxes on production (net) - in proportion to income
gen ch_labor_imputed_tax = ch_net_prod_tax / (ch_B2nS14_vgr + ch_D4S14_recieved_vgr - ch_D4S14_paid_vgr + ch_priminc_corpS + ch_D1S1_vgr) * (ch_D1S1_vgr) 

*** Pre-tax personal factor capital income
gen pretax_capInc = ch_B2nS14_vgr + ch_D4S14_recieved_vgr - ch_D4S14_paid_vgr + ch_priminc_corpS + ch_cap_imputed_tax

*** Pre-tax personal factor labor income
gen pretax_laborInc = ch_D1S1_vgr + ch_labor_imputed_tax

*** Pre-tax factor income
gen pretax_Inc = pretax_capInc + pretax_laborInc

*** Capital and labor shares (as alvaredo et al. 2017)
gen ch_capital_sh = pretax_capInc / pretax_Inc
gen ch_labor_sh = pretax_laborInc / pretax_Inc
label variable ch_capital_sh "Capital Share in National Income - following alvaredo et al."
label variable ch_labor_sh "Labor Share in National Income - following alvaredo et al."

*** alternative capital and labor shares
gen ch_labor_sh2 = ch_D1S1_vgr / ch_nni_vgr
gen ch_capital_sh2 = 1 - ch_labor_sh2
label variable ch_capital_sh2 "Capital Share in National Income - 1 minus ratio labor compensation/national income"
label variable ch_labor_sh2 "Labor Share in National Income - ratio labor compensation/national income"


drop ch_net_prod_tax ch_priminc_corpS ch_cap_imputed_tax ch_labor_imputed_tax pretax_capInc pretax_laborInc pretax_Inc ch_nni_vgr ch_D1S1_vgr ch_B2nS14_vgr ch_D4S14_recieved_vgr ch_D4S14_paid_vgr ch_B5S11_vgr ch_B5S12_vgr ch_D2S13_vgr ch_D3S13_vgr



*****************************
*****   Savings Rates   *****
*****************************
gen ch_saveR_corp_nonfin = ch_B8nS11_save_vgr / ch_nni_T
gen ch_saveR_corp_fin = ch_B8nS12_save_vgr / ch_nni_T
gen ch_saveR_corp = ch_saveR_corp_nonfin + ch_saveR_corp_fin
gen ch_saveR_HH = ch_B8nS14_save_vgr / ch_nni_T
gen ch_saveR_nP = ch_B8nS15_save_vgr / ch_nni_T
gen ch_saveR_HH_nP = ch_saveR_HH + ch_saveR_nP
gen ch_saveR_p = ch_saveR_corp + ch_saveR_HH_nP
gen ch_saveR_g = ch_B8nS13_save_vgr / ch_nni_T
gen ch_saveR_n = ch_saveR_p + ch_saveR_g
gen ch_control = ch_saveR_n - (ch_B8nS1_save_vgr/ch_nni_T)

drop ch_B8nS13_save_vgr ch_B8nS14_save_vgr ch_B8nS12_save_vgr ch_B8nS11_save_vgr ch_control ch_B8nS15_save_vgr ch_B8nS1_save_vgr
  
label variable ch_saveR_corp_nonfin "non-financial corporate savings in % net national income"
label variable ch_saveR_corp_fin "financial corporate savings in % net national income"
label variable ch_saveR_corp "corporate savings in % net national income"
label variable ch_saveR_HH "household savings in % net national income"
label variable ch_saveR_nP "NPISH savings in % net national income"
label variable ch_saveR_HH_nP "household and NPISH savings in % net national income"
label variable ch_saveR_p "private savings in % net national income"
label variable ch_saveR_g "public savings in % net national income"
label variable ch_saveR_n "national savings in % net national income"




*******************************************
***** Wealth Income Ratios Switzerland*****
*******************************************

*** Private Wealth and components
gen ch_pWIR_schmidt = ch_pW_netW_schmidt / ch_nni_T
gen ch_pWIR = ch_pW_T / ch_nni_T 
gen ch_pWIR_housing = ch_pW_housing_T / ch_nni_T 
gen ch_pWIR_pension = ch_pW_pension_T / ch_nni_T
gen ch_pWIR_netfin = ch_pW_netfin_T / ch_nni_T
gen ch_pWIR_grossfin = ch_pW_grossfin_T / ch_nni_T
gen ch_pWIR_liabil = ch_pW_liabil_T / ch_nni_T
replace ch_pWIR_bruelhart = ch_pWIR_bruelhart / 100

label variable ch_pWIR_schmidt "Private Wealth-Income Ratio - Estimates Schmidt"
label variable ch_pWIR "Net Private Wealth-Income Ratio"
label variable ch_pWIR_housing "Private Housing Wealth-Income Ratio"
label variable ch_pWIR_pension "Private Pension Wealth-Income Ratio"
label variable ch_pWIR_netfin "Private Net-financial Wealth-Income Ratio"
label variable ch_pWIR_grossfin "Private Gross-financial Wealth-Income Ratio"
label variable ch_pWIR_liabil "Private Liabilities Wealth-Income Ratio"
label variable ch_pWIR_bruelhart "Private Wealth-Income Ratio - Estimates Bruelhart et al."


*** Public Wealth and components
***Municipalities
gen ch_gWIR_nonfin_gdn = ch_gW_nonfin_gdn / ch_nni_T
gen ch_gWIR_fin_gdn = ch_gW_fin_gdn / ch_nni_T
gen ch_gWIR_liab_gdn = ch_gW_liab_gdn / ch_nni_T
gen ch_gWIR_net_gdn = ch_gW_net_gdn / ch_nni_T

label variable ch_gWIR_nonfin_gdn "Public non-financial Wealth-Income Ratio - Municipality-level"
label variable ch_gWIR_fin_gdn "Public Financial Wealth-Income Ratio - Municipality-level"
label variable ch_gWIR_liab_gdn "Public Liabilites Wealth-Income Ratio - Municipality-level"
label variable ch_gWIR_net_gdn "Public Net Wealth-Income Ratio - Municipality-level"


***Cantonal-level (state-level)
gen ch_gWIR_nonfin_ktn = ch_gW_nonfin_ktn / ch_nni_T
gen ch_gWIR_fin_ktn = ch_gW_fin_ktn / ch_nni_T
gen ch_gWIR_liab_ktn = ch_gW_liab_ktn / ch_nni_T
gen ch_gWIR_net_ktn = ch_gW_net_ktn / ch_nni_T

label variable ch_gWIR_nonfin_ktn "Public non-financial Wealth-Income Ratio - Cantonal-level"
label variable ch_gWIR_fin_ktn "Public Financial Wealth-Income Ratio - Cantonal-level"
label variable ch_gWIR_liab_ktn "Public Liabilites Wealth-Income Ratio - Cantonal-level"
label variable ch_gWIR_net_ktn "Public Net Wealth-Income Ratio - Cantonal-level"


***Federal-level
gen ch_gWIR_nonfin_bund = ch_gW_nonfin_bund / ch_nni_T
gen ch_gWIR_fin_bund = ch_gW_fin_bund / ch_nni_T
gen ch_gWIR_liab_bund = ch_gW_liab_bund / ch_nni_T
gen ch_gWIR_net_bund = ch_gW_net_bund / ch_nni_T
gen ch_gWIR_nonfin_bund_cor = ch_gW_nonfin_bund_cor / ch_nni_T
gen ch_gWIR_net_bund_cor = ch_gW_net_bund_cor / ch_nni_T

label variable ch_gWIR_nonfin_bund "Public non-financial Wealth-Income Ratio - Federal-level"
label variable ch_gWIR_fin_bund "Public Financial Wealth-Income Ratio - Federal-level"
label variable ch_gWIR_liab_bund "Public Liabilites Wealth-Income Ratio - Federal-level"
label variable ch_gWIR_net_bund "Public Net Wealth-Income Ratio - Federal-level"
label variable ch_gWIR_nonfin_bund_cor "Corrected Public non-financial Wealth-Income Ratio - Federal-level"
label variable ch_gWIR_net_bund_cor "Corrected Public Net Wealth-Income Ratio - Federal-level"


***Public Social Insurance
gen ch_gWIR_nonfin_sv = ch_gW_nonfin_sv / ch_nni_T
gen ch_gWIR_fin_sv = ch_gW_fin_sv / ch_nni_T
gen ch_gWIR_liab_sv = ch_gW_liab_sv / ch_nni_T
gen ch_gWIR_net_sv = ch_gW_net_sv / ch_nni_T

label variable ch_gWIR_nonfin_sv "Public Social Insurance Non-financial Wealth-Income Ratio"
label variable ch_gWIR_fin_sv "Public Social Insurance Financial Wealth-Income Ratio"
label variable ch_gWIR_liab_sv "Public Social Insurance Liabilities Wealth-Income Ratio"
label variable ch_gWIR_net_sv "Public Social Insurance Net Wealth-Income Ratio"


*** Public Wealth total
gen ch_gWIR_nonfin_staat = ch_gW_nonfin_staat / ch_nni_T
gen ch_gWIR_fin_staat = ch_gW_fin_staat / ch_nni_T
gen ch_gWIR_liab_staat = ch_gW_liab_staat / ch_nni_T
gen ch_gWIR_net_staat = ch_gW_net_staat / ch_nni_T 
gen ch_gWIR_nonfin_staat_cor = ch_gW_nonfin_staat_cor / ch_nni_T
gen ch_gWIR_net_staat_cor = ch_gW_net_staat_cor / ch_nni_T 
 
label variable ch_gWIR_nonfin_staat "Public non-financial Wealth-Income Ratio - Total Government"
label variable ch_gWIR_fin_staat "Public Financial Wealth-Income Ratio - Total Government"
label variable ch_gWIR_liab_staat "Public Liabilites Wealth-Income Ratio - Total Government"
label variable ch_gWIR_net_staat "Public Net Wealth-Income Ratio - Total Government"
label variable ch_gWIR_nonfin_staat_cor "Corrected Public non-financial Wealth-Income Ratio - Total Government"
label variable ch_gWIR_net_staat_cor "Corrected Public Net Wealth-Income Ratio - Total Government"
 

*** National Wealth and components
gen ch_nWIR_T = ch_nW_T / ch_nni_T
gen ch_nfaWIR_T = ch_nfaW_T / ch_nni_T
gen ch_domWIR_T = ch_domW_T / ch_nni_T

label variable ch_nWIR_T "National Wealth-Income Ratio"
label variable ch_nfaWIR_T "Net Foreign Wealth-Income Ratio"
label variable ch_domWIR_T "Domestic Wealth-Income Ratio"

********************************************************************************
*** Merge with WID-Data
cd "$mypath/raw_data/wid_world/"
merge 1:1 year using "WID.dta"
drop _merge
********************************************************************************
*** Save final dataset
cd "$mypath/final_data/"
save "WIR_final.dta", replace
********************************************************************************
cd "$mypath/"


